package com.example.lifecycle.base;

import android.arch.lifecycle.LifecycleActivity;
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.example.lifecycle.app.MyApplication;
import com.example.lifecycle.di.AppComponent;


public class BaseActivity extends AppCompatActivity implements LifecycleRegistryOwner {

    private final LifecycleRegistry mRegistry = new LifecycleRegistry(this);

    @Override
    public LifecycleRegistry getLifecycle() {
        return mRegistry;
    }

    public AppComponent getAppComponent() {
        return ((MyApplication) this.getApplication()).getAppComponent();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("####Activity " + getClass().getSimpleName() + " onCreate");
    }

    @Override
    protected void onStart() {
        super.onStart();
        System.out.println("####Activity " + getClass().getSimpleName() + " onStart");

    }

    @Override
    protected void onResume() {
        super.onResume();
        System.out.println("####Activity " + getClass().getSimpleName() + " onResume");

    }

    @Override
    protected void onPause() {
        super.onPause();
        System.out.println("####Activity " + getClass().getSimpleName() + " onPause");

    }

    @Override
    protected void onStop() {
        super.onStop();
        System.out.println("####Activity " + getClass().getSimpleName() + " onStop");

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.out.println("####Activity " + getClass().getSimpleName() + " onDestroy");

    }
}
